/*
 *@Author: 张楚
 *@Date: 2021-08-16 15:15:49
 *@Description: 每个tabview的框框
*/
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:totaldemo/utils/util.dart';

class TabViewItemWidget extends StatefulWidget {
  //公文标题
  String title;
  //紧急程度,1为特急,2为急件,3为平件
  String urgencyState;
  //发文机关
  String documentOffice;
  //创建时间
  String createTime;
  //发文渠道，1为线上，2为线下
  String channel;
  //归档状态。1为已保存，2为处理中,3为已归档,保存为草稿箱就传1
  bool isShowPublishState = false; //看看是否需要显示归档状态
  int publishState;
  TabViewItemWidget(
      {Key key,
      this.title,
      this.urgencyState,
      this.documentOffice,
      this.createTime,
      this.channel,
      this.isShowPublishState,
      this.publishState})
      : super(key: key);

  @override
  _TabViewItemWidgetState createState() => _TabViewItemWidgetState();
}

class _TabViewItemWidgetState extends State<TabViewItemWidget> {
  //紧急状态
  String urgencyState;
  String channel;
  bool changeState = false;
  @override
  Widget build(BuildContext context) {
    //判断是否归档状态
    if (widget.publishState == 2) {
      //显示归档状态为处理中
      setState(() {
        changeState = true;
      });
    } else if (widget.publishState == 3) {
      //显示归档状态为已归档
      setState(() {
        changeState = false;
      });
    }

    ///判断渠道的
    if (widget.channel == '1') {
      setState(() {
        channel = '线上';
      });
    } else if (widget.channel == '2') {
      setState(() {
        channel = '线下';
      });
    }

    ///显示紧急状态的
    switch (widget.urgencyState) {
      case '1':
        {
          setState(() {
            urgencyState = '特急';
          });
        }

        break;
      case '2':
        {
          setState(() {
            urgencyState = '急件';
          });
        }

        break;
      case '3':
        {
          setState(() {
            urgencyState = '平件';
          });
        }

        break;
      default:
    }
    return Container(
      margin: EdgeInsets.only(top: 15, left: 15, right: 15),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(
          Radius.circular(1),
        ),
        color: Colors.white,
        border: Border.all(width: 0.01),
        boxShadow: [
          BoxShadow(
            color: Colors.black12.withOpacity(0.07),
            offset: Offset(0, 0), //阴影xy轴偏移量
            blurRadius: 1.5, //阴影模糊程度
            spreadRadius: 1.5, //阴影扩散程度
          ),
        ],
      ),
      child: Stack(
        children: [
          Container(
            padding: EdgeInsets.only(top: 21, left: 16, bottom: 20),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: 254,
                  child: Text(
                    widget.title,
                    style: TextStyle(
                        fontSize: 14,
                        color: Color(0xff3A3A3A),
                        fontWeight: FontWeight.w500),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 10, bottom: 6),
                  child: Row(
                    children: [
                      Text(
                        urgencyState,
                        style: widget.urgencyState == '3'
                            ? TextStyle(
                                fontSize: 12,
                                color: Color(0xffFF9629),
                                fontWeight: FontWeight.w500)
                            : TextStyle(
                                fontSize: 12,
                                color: Color(0xffFF6E64),
                                fontWeight: FontWeight.w500),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(left: 36),
                        child: Text(
                          widget.documentOffice,
                          style: TextStyle(
                              fontSize: 12,
                              color: Color(0xff666666),
                              fontWeight: FontWeight.w500),
                        ),
                      )
                    ],
                  ),
                ),
                DefaultTextStyle(
                  style: TextStyle(fontSize: 12, color: Color(0xffA3A3A3)),
                  child: Row(
                    // mainAxisAlignment: MainAxisAlignment.end,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Text(widget.createTime),
                      SizedBox(width: 11),
                      Text(channel)
                    ],
                  ),
                )
              ],
            ),
          ),
          //归档状态
          Positioned(
            top: 20,
            right: 0,
            child: Offstage(
              offstage: !widget.isShowPublishState,
              child: changeState
                  ? Image.asset(
                      Util.getUrl('File_status_pending.png'),
                      width: 50,
                      height: 20,
                    )
                  : Image.asset(
                      Util.getUrl('File_status_complete.png'),
                      width: 50,
                      height: 20,
                    ),
            ),
          ),
          //水印
          widget.urgencyState == '1'
              ? Positioned(
                  right: 0,
                  bottom: 0,
                  child: Image.asset(
                    Util.getUrl('official_detail_urgent.png'),
                    width: 50,
                    height: 50,
                  ))
              : Container()
        ],
      ),

      //右上角归档状态
    );
  }
}
